<?php
/**
 *  
 *
  */
namespace Org\Util;
class Jshk6 {

    
     public function hk6_balance() {
		$condition['c_id']=12;
		$condition['status']=0;
 		$order=M('lottery_order')->where($condition)->select();  //所有没有结算订单
		
		$period=M('lottery_order')->distinct(true)->field('c_no')->where($condition)->select();  //没结算期数
		foreach($period as $k=>$v){
 		  $condition1['c_id']=12;
		  $condition1['c_no']=$v['c_no'];
		  $cqssc_result[$v['c_no']]=M('lottery_results')->where($condition1)->getField('lottery_result');  //根据期数获取开奖结果
 		}
		
		foreach($order as $ok=>$ov){
			
 		   if($cqssc_result[$ov['c_no']]){    //有开奖结果才结算
		     
 		      $this->jiesuan($cqssc_result[$ov['c_no']],$ov);
			
			  }
 		}
		return; 		
     }
	
	 public function jiesuan($result,$info=array())
	 {
		 
		 $num= explode(",",$result);
		 $sum=array_sum($num);
 		 
		 //连码
		
		  if(substr($info['w_type'],0,2)=='LM'){
 			 $this->lm($num,$info);
			 
			 }
		
		
		 //正码玩法 ZM
		 if($info['w_type']=='ZM'){
			 
 			 $this->zm($num,$info);
			 }
		 
		
		 //龙虎和玩法 LH L H T
		  if($info['w_type']=='LH'){
		   $this->lht($num,$info);
		   }
		   //特码A、B
		   if($info['w_type']=='TMA'||$info['w_type']=='TMB'){
			   $this->tmab($num,$info); 
		   }
		   /* 特码大小单双、合单双 */
		   if($info['w_type']=='DX'){
			 if($num[6]==49){
					//和
				   $this->he($info);
				}else{
					
				
				
					 if($num[6]>=24){
					   $bds='D';	 
						 }else{
						$bds='X';	 
							 }
							 
				if($bds==$info['t_type']){  //中奖
				  $this->zhongjiang($info);
				  }else{
				  //不中奖  判断是否反水
				  $this->fanshui($info);
				 }  
		   }}
		    if($info['w_type']=='DS'){
			   if($num[6]==49){
					//和
				   $this->he($info);
				}else{
				
					 if($num[6]%2==0){
					   $bds='S';	 
						 }else{
						$bds='D';	 
							 }
							 
				if($bds==$info['t_type']){  //中奖
				  $this->zhongjiang($info);
				  }else{
				  //不中奖  判断是否反水
				  $this->fanshui($info);
				 }  
			}}
		    if($info['w_type']=='HDS'){
			  if($num[6]==49){
					//和
				   $this->he($info);
				}else{
					
				
				$sum=$num[6]%10+$num[6]/10%10;
					 if($sum%2==0){
					   $bds='S';	 
						 }else{
						$bds='D';	 
							 }
							 
				if($bds==$info['t_type']){  //中奖
				  $this->zhongjiang($info);
				  }else{
				  //不中奖  判断是否反水
				  $this->fanshui($info);
				 }   
			}}
		    if($info['w_type']=='HDX'){
				if($num[6]==49){
					//和
				   $this->he($info);
				}else{
				$sum=$num[6]%10+$num[6]/10%10;
					 if($sum%2>=7){
					   $bds='D';	 
						 }else{
						$bds='X';	 
							 }
							 
				if($bds==$info['t_type']){  //中奖
				  $this->zhongjiang($info);
				  }else{
				  //不中奖  判断是否反水
				  $this->fanshui($info);
				 }  
			}}
		    if($info['w_type']=='TDXDS'){
			  $num=$num[6];
			  if($num>24&&$num<49){
				  //特大
				   if($num%2==0){
					$ds='DS';
						}else{
						
				  $ds='DD';		
					}
				 if($ds==$info['t_type']){  //中奖
						  $this->zhongjiang($info);
						  }else{
						  //不中奖  判断是否反水
								  $this->fanshui($info);
						 }
			  }elseif($num<=24){
				  //特小
				   if($num%2==0){
					$ds='XS';
						}else{
						
				  $ds='XD';		
					}
				 if($ds==$info['t_type']){  //中奖
						  $this->zhongjiang($info);
						  }else{
						  //不中奖  判断是否反水
								  $this->fanshui($info);
						 }
			  }else{
				  //和
				   $this->he($info);
				  
			  }
		   }
		  
		    if($info['w_type']=='WDX'){
			
				 $w=substr($num[6],-1);
					  
						  if($w>4){
							 $dx='D';	 
							}else{
							 $dx='X';	 
							}
						  if($dx==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }			  
		   }
		    //总和大小玩法 ZDX
		 if($info['w_type']=='ZDX'){
 			 $this->zh_dx($sum,$info);
			 }
			//总和单双玩法 ZDS
		 if($info['w_type']=='ZDS'){
			 $this->zh_ds($sum,$info);
			 }
			 
			/*  特天地生肖、前后、家禽野兽 */
			if($info['w_type']=='TDX'){
			$n_lm=$this->zh_zodiac($num);//生肖
			$animal=explode(',',$n_lm);
 			 $te=$animal[6];
			 if(in_array($te,array('兔','马','猴','猪','牛','龙' ))){
				  $te_sx='T';
			  }else{
				  $te_sx='D';
			  }
			  if($te_sx==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }			  
			 } 
			 
			 if($info['w_type']=='QHX'){
			$n_lm=$this->animal_array();//当前12生肖
			$qian[]=$n_lm[0];
			$qian[]=$n_lm[1];
			$qian[]=$n_lm[2];
			$qian[]=$n_lm[3];
			$qian[]=$n_lm[4];
			$qian[]=$n_lm[5];
 			 $te=$animal[6];
			 if(in_array($te,$qian)){
				  $te_sx='Q';
			  }else{
				  $te_sx='H';
			  }
			  if($te_sx==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }			  
			 }
			 if($info['w_type']=='JQYS'){
			$n_lm=$this->zh_zodiac($num);//生肖
			$animal=explode(',',$n_lm);
 			 $te=$animal[6];
			 if(in_array($te,array('牛','马','羊','猪','鸡','狗'))){
				  $te_sx='JQ';
			  }else{
				  $te_sx='YS';
			  }
			  if($te_sx==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }			  
			 } 
		   /*  特天地生肖、前后、家禽野兽 end */
		   
		   /* 特码红波、半波半半波 */
		  if($info['w_type']=='SB'){
			  	if($num[6]==49){
					//和
				   $this->he($info);
				}else{
			 $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
			$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
			$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49); 
			$num=$num[6];
				if(in_array($num,$red)){
					$color='R';
					
			}elseif(in_array($num,$green)){
				 $color='G';
			}else{
				$color='B';
					 
			}
			 if($color==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }
		  }}
		   if($info['w_type']=='BBDS'){
			    if($info['w_type']=='BBDX'){
			   	if($num[6]==49){
					//和
				   $this->he($info);
				
				}else{
			 $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
			$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
			$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49); 
			$num=$num[6];
			
				if(in_array($num,$red)){
					$color='R';
					
			}elseif(in_array($num,$green)){
				 $color='G';
			}else{
				$color='B';
					 
			}
			 if($num%2==0){
					   $bds='S';	 
						 }else{
						$bds='D';	 
							 }
				$cbd=$color.$bds;	 
			 if($cbd==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }
					
			
				}}
		   
		   if($info['w_type']=='BBDX'){
			   	if($num[6]==49){
					//和
				   $this->he($info);
				
				}else{
			 $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
			$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
			$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49); 
			$num=$num[6];
			$sum=$num[6]%10+$num[6]/10%10;
				if(in_array($num,$red)){
					$color='R';
					
			}elseif(in_array($num,$green)){
				 $color='G';
			}else{
				$color='B';
					 
			}
			 if($sum>=24){
					   $bdx='D';	 
						 }else{
						$bdx='X';	 
							 }
				$cbd=$color.$bdx;	 
			 if($cbd==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }
					
		   }
		  }
		   
		   
		 //1-8球玩法  B1-5  0-9球  大小单双
		 for($i=1;$i<=6;$i++){
 			  if($info['w_type']=='DX'.$i){ //1-8大小
			 
			   $this->bdx($num,$info);
			   }
			   
			   if($info['w_type']=='DS'.$i){ //1-8单双
			   $this->bds($num,$info);
			   } 
			    if($info['w_type']=='WDX'.$i){ //1-8尾大小
			   $this->bdx_w($num,$info);
			   } 
			   if($info['w_type']=='B'.$i){ //1-8 号码
			   $this->ball($num,$info);
			   }
			   if($info['w_type']=='HDS'.$i){ //1-8 合数单双号码
			   $this->bds_h($num,$info);
			   }
			    if($info['w_type']=='ZFB'.$i){ //1-8 中发白
			   $this->b_zfb($num,$info);
			   }
			    if($info['w_type']=='FW'.$i){ //1-8 东南西北
			   $this->b_dnxb($num,$info);
			   }
			   
			 
			 }
		 
 		 }
		  //半半波
		  if($info['w_type']=='BBB'){
			  	if($num[6]==49){
					//和
				   $this->he($info);
				}else{
			 $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
			$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
			$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49); 
			$num=$num[6];
				if(in_array($num,$red)){
					$color='R';
					
			}elseif(in_array($num,$green)){
				 $color='G';
			}else{
				$color='B';
					 
			}
			if($num>=24){
				$dx='D';
			}else{
				$dx='X';
			}
			if($num%2==0){
				$ds='S';
			}else{
				$ds='D';
			}
			$cds=$color.$dx.$ds;
			 if($cds==$info['t_type']){  //中奖
						  
							  $this->zhongjiang($info);
							  }else{
							  //不中奖  判断是否反水
								 $this->fanshui($info);
								 
							 }
		  }}
		   
		   //特肖头尾数
		   if($info['w_type']=='SX'){
			   $animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
			$animal_array=explode('>',$animal);
			$n_lm=$this->zh_zodiac($num);//生肖
			$animal=explode(',',$n_lm);
 			 $sx=$animal[6];
			 if($sx==$animal_array[$info['t_type']]){
				//中奖
		 
			  $this->zhongjiang($info); 
			 }else{
				//不中奖  判断是否反水
 			     $this->fanshui($info); 
			 }
			
			
			
		   }
		   //头数
		   if($info['w_type']=='TMTS'){
			   $num=$num[6];
			   if($num<10){
				   $ts=0;
			   }elseif(9<$num&&$num<20){
				   $ts=1;
			   }elseif(19<$num&&$num<30){
				    $ts=2;
			   }elseif(29<$num&&$num<40){
				    $ts=3;
			   }else{
				   $ts=4;
			   }
			  if($ts==$info['t_type']){
				//中奖
		  
			  $this->zhongjiang($info);
			}else{
				//不中奖  判断是否反水
 			     $this->fanshui($info);
			} 
			   
		   }
		 
		   //尾数
		   if($info['w_type']=='TMWS'){
			   $num=$num[6];
			   if($num%10==0){
				   $ws=0;
			   }elseif($num%10==1){
				   $ws=1;
			   }elseif($num%10==2){
				   $ws=2;
			   }elseif($num%10==3){
				   $ws=3;
			   }elseif($num%10==4){
				   $ws=4;
			   }elseif($num%10==5){
				   $ws=5;
			   }elseif($num%10==6){
				   $ws=6;
			   }elseif($num%10==7){
				   $ws=7;
			   }elseif($num%10==8){
				   $ws=8;
			   }elseif($num%10==9){
				   $ws=9;
			   }
			     if($ws==$info['t_type']){
				//中奖
		  
			  $this->zhongjiang($info);
			}else{
				//不中奖  判断是否反水
 			     $this->fanshui($info);
			} 
			   
		   }
		   //合肖
		   if($info['w_type']=='HX'){
			   if($num[6]==46){
				   $this->he($info);  
			   }else{
			$n_lm=$this->zh_zodiac($num);//生肖  
			$animal=explode(',',$n_lm);
 			$te=$animal[6];
			$animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
			$animal_array=explode('>',$animal);
			$animal_num=array();
			$t_type=explode(',',$info['t_type']);
			foreach($t_type as $k=>$v){
				$animal_num[]=$animal_array[$v];
			}
			
			if(in_array($te,$animal_num)){
				//中奖
		  
			  $this->zhongjiang($info);
			}else{
				//不中奖  判断是否反水
 			     $this->fanshui($info); 
			}
		   }}
		   
		   
		    //正码玩法 ZM
		 if($info['w_type']=='ZM'){
			if(in_array($info['t_type'],$num)){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 }
			 }
			 //正码特
			 if(substr($info['w_type'],0,3)=='ZMT'){
				 $number=substr($info['w_type'],-1)-1;
			if($info['t_type']==$num[$number]){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 }
			 } 
			 if(substr($info['w_type'],0,4)=='ZMDX'){
				 $number=substr($info['w_type'],-1)-1;
				if($num[$number]>=24){
					$dx='D';
				} else{
					$dx='X';
				}
			if($dx==$info['t_type']){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 }
			 }
			  if(substr($info['w_type'],0,4)=='ZMWDX'){
				 $number=substr($info['w_type'],-1)-1;
				if(substr($num[$number],-1)>=5){
					$dx='D';
				} else{
					$dx='X';
				}
			if($dx==$info['t_type']){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 }
			 }
			  if(substr($info['w_type'],0,4)=='ZMDS'){
				 $number=substr($info['w_type'],-1)-1;
				if($num[$number]%2==0){
					$ds='S';
				}else{
					$ds='D';
				} 
			if($ds==$info['t_type']){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 }
			 }
			 if(substr($info['w_type'],0,4)=='ZHDS'){
				 $number=substr($info['w_type'],-1)-1;
				$sum=$num[$number]%10+$num[$number]/10%10;
					 if($sum%2==0){
					   $ds='S';	 
						 }else{
						$ds='D';	 
							 } 
			if($ds==$info['t_type']){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 } 
			 }
			 if(substr($info['w_type'],0,4)=='ZMSB'){
				 $number=substr($info['w_type'],-1)+1;
				 $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
			$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
			$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49); 
					 if(in_array($num[$number],$red)){
					   $color='R';	 
						 }elseif(in_array($num[$number],$blue)){
							$color='B';	  
						 }else{
						$color='G';	 
							 } 
			if($color==$info['t_type']){  //中奖
		
		  $this->zhongjiang($info);
		  }else{
		  //不中奖  判断是否反水
		  $this->fanshui($info);
		 } 
			 }
			  /* 正码特end */
			  //五行 金木水火土
			   if($info['w_type']=='WX'){
				   $wx[0]=array(01,02,15,16,23,24,31,32,45,46);
				   $wx[1]=array(05,06,13,14,27,28,35,36,43,44);
				   $wx[2]=array(03,04,11,12,19,20,33,34,41,42,49);
				   $wx[3]=array(07,08,21,22,29,30,37,38);
				   $wx[4]=array(09,10,17,18,25,26,39,40,47,48);
				   $num=$num[6];
				   $wx_num=10;
				   foreach($wx as $k=>$v){
					   if(in_array($num,$v)){
						   $wx_num=$k;
					   }
				   }
				   if($wx_num==$info['t_type']){
					  $this->zhongjiang($info); 
				   }else{
					  $this->fanshui($info); 
				   }
			   }
			  /* 五行end */
			  
			  /* 一肖总肖平特尾数 */
			if($info['w_type']=='YX'){
			$animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
			$animal_array=explode('>',$animal);
			$n_lm=$this->zh_zodiac($num);//生肖
			$animal=explode(',',$n_lm);
			$animal_name=$animal_array[$info['t_type']];
			if(in_array($animal_name,$animal)){
				//中奖
		  
			  $this->zhongjiang($info);
			}else{
				//不中奖  判断是否反水
 			     $this->fanshui($info); 
			}
			
			}

			if($info['w_type']=='WS'){
				foreach($num as $k=>$v){
					$ws=substr($v,-1);
					if($ws==$info['t_type']){
						$ws=10;
						break;
					}
				}
				if($ws==10){
					$this->zhongjiang($info);
				}else{
					 $this->fanshui($info); 
				}
				
			}
			//总肖
			if($info['w_type']=='ZSX'){
				$n_lm=$this->zh_zodiac($num);//生肖  
				
				  $array=explode(',',$n_lm);
				  $array=array_unique($array);
				  $count=count($array);
				  if($count==$info['t_type']){
					   $this->zhongjiang($info);
				  }else{
					   $this->fanshui($info); 
				  }
			}
			if($info['w_type']=='ZSXDS'){
				$n_lm=$this->zh_zodiac($num);//生肖  
				
				  $array=explode(',',$n_lm);
				  $array=array_unique($array);
				  $count=count($array);
				  if($count%2==0){
					  $ds='S';
				  }else{
					  $ds='D';
				  }
				  if($ds==$info['t_type']){
					   $this->zhongjiang($info);
				  }else{
					   $this->fanshui($info); 
				  }
			}
			 /* 一肖总肖平特尾数end */
			 //正肖七色波
			 if($info['w_type']=='ZX'){
				$animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
			    $animal_array=explode('>',$animal);
				$t_type=$info['t_type'];
				$animal_name[]=$animal_array[$t_type];
				
				$animal=$this->zh_zodiac($num);
				$animal=explode(',',$animal);
				$animal_new[]=$animal[0];
				$animal_new[]=$animal[1];
				$animal_new[]=$animal[2];
				$animal_new[]=$animal[3];
				$animal_new[]=$animal[4];
				$animal_new[]=$animal[5];
				$intersection = array_intersect($animal, $animal_name);
				$count=count($intersection);
			
				
				 if($count>0){
					 $this->zhongjiang_zx($info,$count);
				 }else{
					//不中奖  判断是否反水
 			     $this->fanshui($info);  
				 }
			 }
			 //七色波
			 if($info['w_type']=='7SB'){
				  $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
					$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
					$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49);
					$red_f=0;
					$blue_f=0;
					$green_f=0;
					foreach($num as $k=>$v){
						if(in_array($v,$red)){
							$red_f+=1;
							if($k==6){
							$red_f+=0.5;	
							}
						}elseif(in_array($v,$green)){
							$green_f+=1;
							if($k==6){
							$green_f+=0.5;	
							}
						}else{
						 $blue_f+=1;
							if($k==6){
							$green_f+=0.5;	
							}		 
						}
					}
					if($red_f>$green_f&&$red_f>$blue_f){
						$color='R';
					}elseif($green_f>$red_f&&$green_f>$blue_f){
						$color='G';
					}else{
						$color='B';
					}
					if($color==$info['t_type']){
						 $this->zhongjiang($info);
					}else{
						 $this->fanshui($info); 
					}
			 }
			 
			/*  正肖七色波 end*/
			//自选不中
			 if($info['w_type']=='ZXBZ'){
				 $t_type=explode(',',$info['t_type']);
				$intersection = array_intersect($num,$t_type);
				$count=count($intersection);
				if($count==0){
					 $this->zhongjiang($info);
				}else{
					$this->fanshui($info); 
				}
			 }
			 //连肖连尾
			  if(substr($info['w_type'],0,2)=='LX'){
				  $n_lm=$this->zh_zodiac($num);//生肖 
				  $animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
				  $animal_array=explode('>',$animal);
				  $t_type=explode(',',$info['t_type']);
				  foreach($t_type as $k=>$v){
					  $t_type[$k]=$animal_array[$v];
				  }
				  $lian=substr($info['w_type'], -1);
				  $n_lm=explode(',',$n_lm);
				  $zhon=array_intersect($t_type,$n_lm);
				
				  if(count($zhon)==$lian){  //中奖
				   $this->zhongjiang($info);
				  }else{
					  //不中奖  判断是否反水
 			     $this->fanshui($info);
				  }
				  
			  }
			   if(substr($info['w_type'],0,2)=='LW'){
				 foreach($num as $k=>$v){
					 $num[$k]=substr($v,-1);
				 }
				 $t_type=explode(',',$info['t_type']);
				  $lian=substr($info['w_type'], -1);
				  $zhon=array_intersect($t_type,$num);
				  if(count($zhon)==$lian){  //中奖
				   $this->zhongjiang($info);
				  }else{
					  //不中奖  判断是否反水
 			     $this->fanshui($info);
				  }
				  
			  }
			 /*  连肖连尾end */
	 } 
			 
		 public function tmab($num,$info){
			 
			 if($num[6]==$info['t_type']){
				 //中奖
		  
			  $this->zhongjiang($info);
			 }else{
				//不中奖  判断是否反水
 			     $this->fanshui($info); 
			 }
		 }
		public function zh_wdx($sum,$info){  //总和大小
		  
	  $w=substr($sum,-1);
	  
          if($w>4){
		     $dx='D';	 
			}else{
			 $dx='X';	 
			}
			
	      if($dx==$info['t_type']){  //中奖
		  
			  $this->zhongjiang($info);
 			  }else{
			  //不中奖  判断是否反水
 			     $this->fanshui($info);
				 
			 }
       } 
		 
	  public function zh_dx($sum,$info){  //总和大小
	  
          if($sum>=84){
		     $dx='D';	 
			}else{
			 $dx='X';	 
			}
			
	      if($dx==$info['t_type']){  //中奖
			  $this->zhongjiang($info);
 			  }else{
			  //不中奖  判断是否反水
 			     $this->fanshui($info);
				 
			 }
       }
    
	public function zh_ds($sum,$info){  //总和单双
      if($sum%2==0){
		$ds='S';
			}else{
			
      $ds='D';		
		}
	 if($ds==$info['t_type']){  //中奖
			  $this->zhongjiang($info);
 			  }else{
			  //不中奖  判断是否反水
 					  $this->fanshui($info);
 			 }
    }
	
	
	 public function zm($num,$info){  //正码
	
 	if(in_array($info['t_type'],$num)){  //中奖
	
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }	 
  }
	 public function lm($num,$info){  //连码
	$t_type=explode(',',$info['t_type']);
	
	$money=round((float)$info['money'],2);
	if($info['w_type']=='LM3Z2'){
		
		$t =$this->getCombinationToString($t_type,3);
		$lost=0;
		$count=count($t);
		$money_win=0;
		$info['money']=round((float)$info['money']/$count,2);
		
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
			
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		  if($count_z==2){
			  //中2
			  $money_win+=round((float)$info['money']*$info['odds'],2); 
			 
		  }elseif($count_z==3){
			  //中3
			 
			  $odds=M('lottery_odds')->where('c_id=12 and w_id=13')->getField('odds'); 
			  $odds= unserialize($odds);
			  $odds_3=$odds[2];
			  $money_win+=round((float)$info['money']*$odds_3,2);
			
		  }else{
			  //不中
			
			$lost++;
		
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
			
	}elseif($info['w_type']=='LM3QZ'){
		$t =$this->getCombinationToString($t_type,3);
		$lost=0;
		$count=count($t);
		$money_win=0;
		$info['money']=round((float)$info['money']/$count,2);
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
			
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		 if($count_z==3){
			  //中3
			 
			  $money_win+=round((float)$info['money']*$info['odds'],2); 
			
		  }else{
			  //不中
			
			$lost++;
			
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
	}elseif($info['w_type']=='LM2QZ'){
		$t =$this->getCombinationToString($t_type,2);
		$lost=0;
		$count=count($t);
		$money_win=0;
		$info['money']=round((float)$info['money']/$count,2);
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
			
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		 if($count_z==2){
			  //中3
			 
			  $money_win+=round((float)$info['money']*$info['odds'],2); 
			
		  }else{
			  //不中
			
			$lost++;
		
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
	}elseif($info['w_type']=='LM2ZT'){
		$t =$this->getCombinationToString($t_type,2);
		$lost=0;
		$count=count($t);
		$money_win=0;
		$info['money']=round((float)$info['money']/$count,2);
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
			
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		 if($count_z==2){
			  //中2
			 if(in_array($num[6],$t_num)){
				 //中特
				 $money_win+=round((float)$info['money']*$info['odds'],2); 
			
			 }else{
				 //中二
				  $odds=M('lottery_odds')->where('c_id=12 and w_id=13 ')->getField('odds');
			  $odds= unserialize($odds);
			  $odds_2=$odds[6];
			  $money_win+=round((float)$info['money']*$odds_2,2);
			 
			 }
			  
		  }else{
			  //不中
			
			$lost++;
		
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
	}elseif($info['w_type']=='LMTC'){
		$t =$this->getCombinationToString($t_type,2);
		$lost=0;
		$count=count($t);
		$money_win=0;
		$info['money']=round((float)$info['money']/$count,2);
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
			
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		 if($count_z==2&&in_array($num[6],$t_num)){
			
			 //中特
				 $money_win+=round((float)$info['money']*$info['odds'],2);  
								 
		  }else{
			  //不中
			
			$lost++;
			
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
	}elseif($info['w_type']=='LM4QZ'){
		$t =$this->getCombinationToString($t_type,4);
		$lost=0;
		$money_win=0;
		$count=count($t);
		$info['money']=round((float)$info['money']/$count,2);
		foreach($t as $k=>$v){
			$t_num=explode(',',$v);
		
			$zhon=array_intersect($t_num,$num);
		  $w=substr($info['w_type'], -1);
		  $count_z=count($zhon);
		 if($count_z>=4){
			  //中4
			  	
			  $money_win+=round((float)$info['money']*$info['odds'],2); 
			  
		  }else{
			  //不中
			
			$lost++;
			
		  }
		}
			$money=$money_win-$money;
			if($money>0){
				$this->zhongjiang_lm($info,$money,$money_win);
			}else{
				//反水比列
				$column=$lost/$count;
				$this->fanshui_lm($info,$column,$money,$money_win);
			}
	}
	
	
 		 
  }
  

 public function lht($num,$info){  //龙虎和
      if($num[0]>$num[7]){
			$lht='L';	 
			 }elseif($num[0]<$num[7]){
				$lht='H';	  
				 }	else{
				$lht='T';	  	 
					 }	
		if($lht==$info['t_type']){  //中奖
			  $this->zhongjiang($info);
 			  }elseif($lht=='T'){
				  //和
				  $this->he($info);
			  }else{
			  //不中奖  判断是否反水
 					  $this->fanshui($info);
 			 }			 
  }
 
 public function bdx($num,$info){  //1-8球大小
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
 		 if($num[$bx]>=11){
		   $bdx='D';	 
			 }else{
			$bdx='X';	 
				 }
 	if($bdx==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }	 
  }
 public function bds($num,$info){  //1-8球单双
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
		 if($num[$bx]%2==0){
		   $bds='S';	 
			 }else{
			$bds='D';	 
				 }
 	if($bds==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }	 
  }	 
   public function bds_h($num,$info){  //1-8球合数单双
	
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
	$num=$num[$bx];
	$sum=$num%10+$num/10%10;
		 if($sum%2==0){
		   $bds='S';	 
			 }else{
			$bds='D';	 
				 }
 	if($bds==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }
		 
	}
    public function bdx_w($num,$info){  //1-8球尾大小
	
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
		 if($num[$bx]>4){
		   $wdx='D';	 
			 }else{
			$wdx='X';	 
				 }
				 if($wdx==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }
		 
	}
	 public function b_dnxb($num,$info){  //1-8球东南西北
	
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
		 if(in_array($num[$bx],array(01,05,09,13,17))){
		   $wdx=0;	 
			 }elseif(in_array($num[$bx],array(02,06,10,14,18))){
				$wdx=1;	 
			 }elseif(in_array($num[$bx],array(03,07,11,15,19))){
				$wdx=2;	 
			 }else{
			$wdx=3;		 
				 }
				 if($wdx==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }
		 
	}
	 public function b_zfb($num,$info){  //1-8球中发白
	
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
		 if(in_array($num[$bx],array(01,02,03,04,05,06,07))){
		   $wdx=0;	 
			 }elseif(in_array($num[$bx],array(08,09,10,11,12,13,14))){
				$wdx=1;	 
			 }elseif(in_array($num[$bx],array(15,16,17,18,19,20))){
				$wdx=2;	 
			 }
				 if($wdx==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }
		 
	}
  
  public function ball($num,$info){  //1-8球单双
	$ax=substr($info['w_type'], -1); 
	$bx=$ax-1;
	 
 	if($num[$bx]==$info['t_type']){  //中奖
	  $this->zhongjiang($info);
	  }else{
	  //不中奖  判断是否反水
	  $this->fanshui($info);
	 }	 
  }	
   public function zhongjiang_lm($info,$money_win,$money){
 	
	//print_r($money);exit;
	$updata_data['is_winning'] = 1;
	$updata_data['status'] = 1;
	$updata_data['win_money'] =$money_win;
	$updata_data['js_time'] = time();
	M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$money); // 用户的余额增加
	//添加余额变动记录
	$insert_log['m_id']=$info['m_id'];
	$insert_log['change_money']=$money;
	$insert_log['change_type']=5;
	$insert_log['add_time']=time();
	$insert_log['remark']='香港六合彩中奖 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
	M('account_log')->add($insert_log);
	 }
	  public function fanshui_lm($info,$column,$money_lost,$money_win){
 	  $updata_data['is_winning'] = 2;
	  $updata_data['status'] = 1;
	  $updata_data['lost_money'] = $money_lost;
	  $updata_data['js_time'] = time();
	
	  if($money_win>0){
		  
			M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$money_win); // 用户的余额增加
			//添加余额变动记录
			$insert_log['m_id']=$info['m_id'];
			$insert_log['change_money']=$money_win;
			$insert_log['change_type']=2;
			$insert_log['add_time']=time();
			$insert_log['remark']='香港六合彩返回余额 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
			M('account_log')->add($insert_log);
	  }
		if($info['rebate']>0){
			$rebate=round((float)$info['rebate']*$column,2);
			 $updata_data['lost_money'] = $money_lost+$rebate;
			
			M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$info['rebate']); // 用户的余额增加
			//添加余额变动记录
			$insert_log['m_id']=$info['m_id'];
			$insert_log['change_money']=$info['rebate'];
			$insert_log['change_type']=2;
			$insert_log['add_time']=time();
			$insert_log['remark']='香港六合彩反水 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
			M('account_log')->add($insert_log);
		}
	
		 M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
		
		
	 }
 public function zhongjiang($info){
	
 	$money=round((float)$info['money']*$info['odds'],2);
	//print_r($money);exit;
	$updata_data['is_winning'] = 1;
	$updata_data['status'] = 1;
	$updata_data['js_time'] = time();
	$updata_data['win_money'] =$money;
	M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$money); // 用户的余额增加
	//添加余额变动记录
	$insert_log['m_id']=$info['m_id'];
	$insert_log['change_money']=$money;
	$insert_log['change_type']=5;
	$insert_log['add_time']=time();
	$insert_log['remark']='香港六合彩中奖 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
	M('account_log')->add($insert_log);
	 }
	 public function zhongjiang_zx($info,$count){
	if($count>0&&$count<=4){
		
	}elseif($count==5){
		$count=4;
	}else{
		$count=1;
	}
 	$money=$info['money']+round((float)$info['money']*$count*($info['odds']-1),2);
	$updata_data['is_winning'] = 1;
	
	$updata_data['is_winning'] = 1;
	$updata_data['win_money'] =$money;
	$updata_data['status'] = 1;
	$updata_data['js_time'] = time();
	M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$money); // 用户的余额增加
	//添加余额变动记录
	$insert_log['m_id']=$info['m_id'];
	$insert_log['change_money']=$money;
	$insert_log['change_type']=5;
	$insert_log['add_time']=time();
	$insert_log['remark']='香港六合彩中奖 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
	M('account_log')->add($insert_log);
	 }
	  
	 public function he($info){
 	$money=$info['money'];
	//print_r($money);exit;
	$updata_data['is_winning'] = 3;
	$updata_data['status'] = 1;
	$updata_data['js_time'] = time();
	M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$money); // 用户的余额增加
	//添加余额变动记录
	$insert_log['m_id']=$info['m_id'];
	$insert_log['change_money']=$money;
	$insert_log['change_type']=5;
	$insert_log['add_time']=time();
	$insert_log['remark']='香港六合彩和 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
	M('account_log')->add($insert_log);
	$updata_data['lost_money'] =$info['money'];
		  M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	 } 
 public function fanshui($info){
 	  $updata_data['is_winning'] = 2;
	  $updata_data['status'] = 1;
	  $updata_data['js_time'] = time();
	  //M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
		if($info['rebate']>0){
			M('member')->where('member_id='.$info['m_id'])->setInc('member_money',$info['rebate']); // 用户的余额增加
			//添加余额变动记录
			$insert_log['m_id']=$info['m_id'];
			$insert_log['change_money']=$info['rebate'];
			$insert_log['change_type']=2;
			$insert_log['add_time']=time();
			$insert_log['remark']='香港六合彩反水 下注期号:'.$info['c_no'].'订单号:'.$info['order_sn'];
			M('account_log')->add($insert_log);
		}
		$updata_data['lost_money'] =$info['money']-$info['rebate'];
		  M('lottery_order')->where('order_id='.$info['order_id'])->save($updata_data); // xi
	 }


  public function getCombinationToString($arr,$m)
		{
			$result = array();
			if ($m ==1)
			{
			   return $arr;
			}
			
			if ($m == count($arr))
			{
				$result[] = implode(',' , $arr);
				return $result;
			}
				
			$temp_firstelement = $arr[0];
			unset($arr[0]);
			$arr = array_values($arr);
			$temp_list1 = $this->getCombinationToString($arr, ($m-1));
			
			foreach ($temp_list1 as $s)
			{
				$s = $temp_firstelement.','.$s;
				$result[] = $s;
			}
			unset($temp_list1);

			$temp_list2 = $this->getCombinationToString($arr, $m);
			foreach ($temp_list2 as $s)
			{
				$result[] = $s;
			}    
			unset($temp_list2);
			
			return $result;
		}
		
		
		
	public function zh_zodiac($num){  //生肖
	$animal_array=$this->animal_array();
	
     foreach($num as $k=>$v){
		 $v=preg_replace('/^0+/','',$v);   //去除左边的0
		 foreach($animal_array as $kk=>$vv){
			 $number=explode(',',$vv['num']);
			  if(in_array($v,$number)){
				  $num[$k]=$vv['animal'];
			  }
		 }
		
	 }
	 $xs=implode(',',$num);
		return $xs;
 }
 //生肖归属
 public function animal_array(){
	 $animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
	 $animal_array=explode('>',$animal);
	 $in[0]='1,13,25,37,49';
	 $in[1]='2,14,26,38';
	 $in[2]='3,15,27,39';
	 $in[3]='4,16,28,40';
	 $in[4]='5,17,29,41';
	 $in[5]='6,18,30,42';
	 $in[6]='7,19,31,43';
	 $in[7]='8,20,32,44';
	 $in[8]='9,21,33,45';
	 $in[9]='10,22,34,46';
	 $in[10]='11,23,35,47';
	 $in[11]='12,24,36,48';
	  
	 
	 $year=date('Y',time());
	
	 $my_animal = ($year-1900)%12;
	 $animal=$animal_array[$my_animal];
	 
	 foreach($animal_array as $k=>$v){
		 if($animal==$v){
			 $num=$k;
			 $k2=$k;
			 for($i=0;$i<=$num;$i++){
				 $kk=$k2;
				$animal_array_new[$i]['animal']=$animal_array[$kk]; 
				$animal_array_new[$i]['num']=$in[$i];
				$k2--;		
			 }
			
			$kkk=11;
			  for($i=$num+1;$i<=11;$i++){
				$animal_array_new[$i]['animal']=$animal_array[$kkk]; 
				$animal_array_new[$i]['num']=$in[$i]; 
				$kkk--;
			 }
			 
		 }
	 }
	
	 
	 return $animal_array_new;
 }
	 
}